<title>用户资金</title>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="financial-balance-index-search_from">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">用户id</label>
                    <div class="layui-input-inline">
                        <input type="text" name="m_id" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="financial-balance-index-search_button">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <script type="text/html" id="financial-balance-index-toolbar_tmp">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="financial-balance-index-add">批量充值</button>
            </div>
        </script>
        <div class="layui-card-body">
            <table id="financial-balance-index" lay-filter="financial-balance-index"></table>
            <script type="text/html" id="financial-balance-index-action_button">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="financial-balance-index-detail">明细</a>
                <a class="layui-btn layui-btn-xs" lay-event="financial-balance-index-recharge">充值</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="financial-balance-index-deduct">扣除</a>
            </script>
        </div>
    </div>
</div>
<script>
    layui.use(['common', 'table'], function () {
        var $ = layui.jquery,
            common = layui.common,
            view = layui.view,
            table = layui.table,
            form = layui.form,
            lay_id_prefix = 'financial-balance-index',//当前页id前缀
            api_action_url = layui.setter.apiHost + '/financial/balance';

        //表单搜索
        form.on('submit(' + lay_id_prefix + '-search_button)', function (data) {
            var field = data.field;
            field.page = 1;//默认第一页
            table.reload(lay_id_prefix, {
                where: field
            });
        });

        //表格操作
        table.render({
            elem: '#' + lay_id_prefix,
            url: api_action_url,
            toolbar: '#' + lay_id_prefix + '-toolbar_tmp',
            cols: [[
                {field: 'id', title: 'ID', width: 80},
                {field: 'username', title: '用户名', minWidth: 170},
                {field: 'amount', title: '账户金额'},
                {field: 'updated_at', title: '最后变更时间', width: 170},
                {title: '操作', width: 170, align: 'center', fixed: 'right', toolbar: '#' + lay_id_prefix + '-action_button'}
            ]],
            page: true
        });

        //头部工具栏操作
        table.on('toolbar(' + lay_id_prefix + ')', function (obj) {
            var type = obj.event;
            switch (type) {
                case lay_id_prefix + '-add':
                    var set_data = {
                        save_url: api_action_url + '/batch_recharge',//保存地址
                    };
                    common.open_window('批量充值', api_action_url, 'financial/balance/add', 'financial-balance-add', set_data);
                    break;
            }
        });

        //监听工具条操作按钮
        table.on('tool(' + lay_id_prefix + ')', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case lay_id_prefix + '-detail':
                    common.open_window('明细', api_action_url, 'financial/balance/detail', 'financial-balance-detail', {width: '100%'}, {m_id: data.m_id});
                    break;
                case lay_id_prefix + '-recharge':
                    var set_data = {
                        save_url: api_action_url + '/recharge',//保存地址
                    };
                    common.open_window('充值', api_action_url, 'financial/balance/recharge', 'financial-balance-recharge', set_data, {m_id: data.m_id});
                    break;
                case lay_id_prefix + '-deduct':
                    var set_data = {
                        save_url: api_action_url + '/deduct',//保存地址
                    };
                    common.open_window('扣除', api_action_url, 'financial/balance/deduct', 'financial-balance-deduct', set_data, {m_id: data.m_id});
                    break;
            }
        });

    });
</script>